package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.Util;
import asteroids.model.CollisionObject;
import asteroids.model.Ship;

public class Inequality extends EqualityExpression {
	public Inequality(E e1, E e2) {
		super(e1, e2);
	}

	public Object inEquality(Map<String,E> map, CollisionObject collisionObject){
		if(getExpression1().getContent(map, collisionObject) instanceof Double && getExpression2().getContent(map, collisionObject) instanceof Double){
			return !Util.fuzzyEquals((double)getExpression1().getContent(map, collisionObject), (double)getExpression2().getContent(map, collisionObject));
		}
		else if(!getExpression1().isNull() && !getExpression2().isNull()&& getExpression1().getContent(map, collisionObject).getClass() == getExpression2().getContent(map, collisionObject).getClass()){
			return!(getExpression1().getContent(map, collisionObject) == getExpression2().getContent(map, collisionObject));
		}

		else if(getExpression1().isNull() && getExpression2().isNull()){
			return !true;
		}
		else if(getExpression1().isNull()){
			if(getExpression2().getContent(map, collisionObject) instanceof Double)
				return !((double)getExpression2().getContent(map, collisionObject) == Double.POSITIVE_INFINITY);
			else if(getExpression1().getContent(map, collisionObject) instanceof CollisionObject){
				return true;
			}
			else{
				if(collisionObject.isShip()){
					Ship ship = (Ship)collisionObject;
					ship.getProgram().setMistake();
				}}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}
		else if(getExpression2().isNull()){
			if(getExpression1().getContent(map, collisionObject) instanceof Double)
				return !((double)getExpression1().getContent(map, collisionObject) == Double.POSITIVE_INFINITY);
			else if(getExpression1().getContent(map, collisionObject) instanceof CollisionObject){
				return true;
			}
			else{
				if(collisionObject.isShip()){
					Ship ship = (Ship)collisionObject;
					ship.getProgram().setMistake();
				}}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return "";
		}
		else if(getExpression2().getContent(map, collisionObject) instanceof Double && getExpression1().getContent(map, collisionObject) instanceof Double){
			return !((double)getExpression1().getContent(map, collisionObject) == Double.POSITIVE_INFINITY 
					&&(double)getExpression1().getContent(map, collisionObject) == Double.POSITIVE_INFINITY);
		}
		else{
			if(collisionObject.isShip()){
				Ship ship = (Ship)collisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return "";
		}
	}

	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject){
		try{
			return inEquality(map,givenCollisionObject);
		}
		catch(NullPointerException exc){
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}
	}
}
